package com.sinosoft.user.api.factory;

import com.alibaba.fastjson.JSONObject;
import com.sinosoft.common.core.domain.R;
import com.sinosoft.system.api.RemoteUserService;
import com.sinosoft.user.api.RemoteFlowService;
import org.apache.poi.ss.formula.functions.T;
import org.flowable.task.api.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 流程服务降级处理
 *
 * @author tangyongbo
 */
@Component
public class RemoteFlowFallbackFactory implements FallbackFactory<RemoteFlowService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteFlowFallbackFactory.class);

    @Override
    public RemoteFlowService create(Throwable throwable)
    {
        log.error("流程服务调用失败:{}", throwable.getMessage());
        return new RemoteFlowService()
        {
            @Override
            public String startProcess(@RequestParam String modelId, @RequestParam String businessKey)
            {
                return "获取用户失败:" + throwable.getMessage();
            }
            @Override
            public JSONObject getTasks(@RequestParam("userKey") String userKey)
            {
                log.error("待办任务获取失败："+throwable.getMessage());
                return null;
            }

            @Override
            public feign.Response flowDiagram(@RequestParam("businessKey") String businessKey){
                log.error("获取流程图失败："+throwable.getMessage());
                return null;
            }

            @Override
            public String completeTask(@RequestParam("taskId") String taskId){
                log.error("完结任务失败："+throwable.getMessage());
                return null;
            }
        };
    }
}
